package org.shop.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.shop.dao.GoodsMapper;
import org.shop.dao.OrderGoodsMapper;
import org.shop.entity.Goods;
import org.shop.entity.OrderGoods;
import org.shop.service.GoodsService;
import org.shop.service.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
public class GoodsServiceImpl extends BaseServiceImpl<Goods, Long> implements GoodsService {

	@Autowired
    private GoodsMapper goodsMapper;
	@Autowired
	private OrderGoodsMapper orderGoodsMapper;
	
	@Override
    public Map<String, Object> getShopGoodsList(Map<String, Object> paramMap) {
        List<Goods> goodsList = goodsMapper.getShopGoodsList(paramMap);
        Integer count = goodsMapper.getShopGoodsCount(paramMap);
        //分页数据
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("total", count);
        dataMap.put("rows", goodsList);
        return dataMap;
    }
	
	@Override
	public List<Goods> getUserGoodsList(Map<String, Object> paramMap) {
		List<Goods> goodsList = goodsMapper.getUserGoodsList(paramMap);
		return goodsList;
	}
	
	@Override
	public List<Map<String, Object>> getGoodsList(Map<String, Object> paramMap) {
		List<Map<String, Object>> list = goodsMapper.getGoodsList(paramMap);
		return list;
	}
	
	@Override
	public List<Map<String, Object>> getUsedGoodsList(Map<String, Object> paramMap) {
		List<Map<String, Object>> list = goodsMapper.getUsedGoodsList(paramMap);
		return list;
	}
	
	@Override
	public Map<String, Object> getUsedGoodsInfo(Map<String, Object> paramMap) {
		Map<String, Object> map = goodsMapper.getUsedGoodsInfo(paramMap);
		return map;
	}

	@Override
	public Map<String, Object> getCheckGoodsList(Map<String, Object> paramMap) {
		List<Map<String, Object>> goodsList = goodsMapper.getCheckGoodsList(paramMap);
        Integer count = goodsMapper.getCheckGoodsCount(paramMap);
        //分页数据
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.put("total", count);
        dataMap.put("rows", goodsList);
        return dataMap;
	}

	@Override
	public List<Map<String, Object>> getAllUsedGoodsList(Map<String, Object> paramMap) {
		return goodsMapper.getAllUsedGoodsList(paramMap);
	}
	
	@Override
	public List<Map<String, Object>> goodsByClassifyList(Map<String, Object> paramMap) {
		List<Map<String, Object>> list = goodsMapper.goodsByClassifyList(paramMap);
		return list;
	}

	@Override
	public int closeThisGoods(Long merchantId) {
		return goodsMapper.closeThisGoods(merchantId);
	}

	@Override
	public int openThisGoods(Long merchantId) {
		return goodsMapper.openThisGoods(merchantId);
	}
	@Transactional(rollbackFor=Exception.class)
	@Override
	public void goodsDown(Goods goods) {
		goodsMapper.updateByPrimaryKeySelective(goods);
		OrderGoods orderGoods=new OrderGoods();
		orderGoods.setState((byte)0);
		orderGoods.setGoodsId(goods.getGoodsId());
		orderGoodsMapper.updateStateByGoodsId(orderGoods);
	}
	
	@Override
    public List<Map<String,Object>> getMerchantGoodsClassifyList(Map<String,Object> params){
		return goodsMapper.getMerchantGoodsClassifyList(params);
	}

}
